<template>
	<view class="wrap">
		<view class="bbs-title">
			<u-row justify="space-between">
				<u-col span="3">
					<view class="demo-layout bell-index">
						<u-image width="48rpx" height="48rpx" src="/static/img/bell_befor.png"></u-image>
						<view style="position: relative" @click="toNews">消息<u-badge :count="notSeeMesge" :absolute="absolute" :is-center="absolute" :offset="bellBage" class="badge-bell"></u-badge></view>
					</view>
				</u-col>
				<u-col span="3" class="bbs-btn">
					<view class="demo-layout">
						<u-button type="primary" size="mini" @click.stop="bbsToPath">发布+</u-button>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="u-card-wrap">
			<u-card :title="item.createUserName" :thumb="thumb" :sub-title="item.createTime" :padding="padding" :border="border" v-for="(item, index) in bbsListData" :key="index" @head-click="bbschart(item)" @body-click="bbschart(item)">
				<template slot="body">
					<view class="mainTitle" style="font-size: 18px; font-weight: 600">{{ item.title }}</view>
					<view class="u-bbslabel" style="margin: 5px 0">
						<u-tag :text="item.contentType" type="primary" size="mini" style="margin-right: 5px" />
						<u-tag :text="item.businessModularType" type="primary" size="mini" />
					</view>
					<view class="u-content" @click.stop>
						<u-parse :html="item.content"></u-parse>
					</view>
					<!-- <view class="fu-text">我是富文本编辑器</view> -->
				</template>
				<template slot="foot">
					<u-icon v-if="bottomSlot" name="chat-fill" size="34" label="评论" @click="bbschart(item)"></u-icon>
					<!-- <u-icon name="thumb-up-fill" size="34" label="点赞" style="margin-left: 30px;"></u-icon> -->
					<u-icon name="trash-fill" size="34" label="删除" style="margin-left: 30px" v-if="kms.bbs.delete" @click="deletebbs(item.bbsId)"></u-icon>
				</template>
			</u-card>
		</view>
		<!-- 功能菜单 -->
		<!-- <u-action-sheet :list="list" v-model="show" @click="selected"></u-action-sheet> -->
		<view class="footer">
			<uni-pagination v-if="totalRow > 0" style="width: 100%" @change="handlePage" show-icon="true" :total="totalRow" pageSize="10" :current="currentPage"></uni-pagination>
		</view>
	</view>
</template>

<script>
// import { mapGetters } from 'vuex';
import { KmsBbsList, KmsDeleteBbs, unreadMessageCount } from '@/api/kms/bbs.js';
export default {
	data() {
		return {
			absolute: true,
			bellBage: [22, -16],
			title: '素胚勾',
			subTitle: '2020-05-15',
			thumb: '/static/kms/not-user.png',
			padding: 20,
			bottomSlot: true,
			border: true,
			Loop: null,
			bbsListData: [],
			list: [
				{
					text: '点赞',
					color: 'blue',
					fontSize: 28,
				},
				{
					text: '分享',
				},
				{
					text: '评论',
				},
			],
			show: false,
			totalRow: 0,
			notSeeMesge: 0,
			currentPage: 1,
			kms: {},
		};
	},
	computed: {
		// ...mapGetters(['kms']),
	},
	onLoad() {},
	onShow() {
		this.getbbsList();
		this.notSeeMesg();
		this.getKMS();
	},
	watch: {},
	methods: {
		// 获取本地存储信息
		async getKMS() {
			this.kms = (await uni.getStorageSync('kms')) || {};
			console.log('login.vue getKMS:', this.kms);
		},
		bbsToPath() {
			let params = {
				crmType: 'bbs',
			};
			uni.navigateTo({
				url: '/pages/kmsManagement/kmsFunList/bbs/publishBbs?params=' + encodeURIComponent(JSON.stringify(params)),
			});
		},
		bbschart(item) {
			uni.navigateTo({
				url: '/pages/kmsManagement/kmsFunList/bbs/bbsDetail?bbsId=' + item.bbsId,
			});
		},
		handlePage(params) {
			this.currentPage = params.current;
			this.getbbsList();
		},
		getbbsList() {
			let self = this;
			let params = {
				type: 103,
				page: this.currentPage,
				limit: 10,
			};
			KmsBbsList(params).then((res) => {
				self.bbsListData = res.data.list;
				self.totalRow = res.data.totalRow;
				// self.showListData = res.data;
				console.log(111);
			});
		},
		deletebbs(id) {
			let self = this;
			let params = {
				bbsId: id,
			};
			KmsDeleteBbs(params).then((res) => {
				self.getbbsList();
			});
		},
		notSeeMesg() {
			let self = this;
			let params = {};
			unreadMessageCount(params).then((res) => {
				self.notSeeMesge = res.data.count;
			});
		},
		toNews() {
			uni.navigateTo({
				url: '/pages/kmsManagement/kmsFunList/bbs/myNews',
			});
		},
	},
	// 页面处理函数--监听用户下拉动作
	onPullDownRefresh() {
		this.currentPage = 1;
		this.getbbsList();
		uni.stopPullDownRefresh();
	},
	// 页面处理函数--监听用户上拉触底
	onReachBottom() {},
};
</script>

<style lang="scss" scoped>
.fu-text {
	background-color: #fab6b6;
	margin: 20rpx 40rpx;
	height: 200rpx;
}
.bbs-title {
	padding: 30rpx 24rpx;
	.demo-layout {
		border-radius: 8rpx;
	}
	.bbs-btn {
		text-align: right !important;
	}
}

.bell-index {
	display: flex;
	align-items: center;
}
.badge-bell {
	top: 5px !important;
	right: -10px !important;
}

.bg-purple {
	background: #d3dce6;
}

.bg-purple-light {
	background: #e5e9f2;
}

.bg-purple-dark {
	background: #99a9bf;
}
.log-unit {
	font-size: 35rpx;
	font-weight: 600;
}
.u-demo {
	padding-top: 0;
}

.u-card-wrap /deep/ {
	// padding: 1px;

	.u-card:first-child {
		margin-top: 0 !important;
	}
}

.u-body-item {
	font-size: 32rpx;
	color: #333;
	padding: 20rpx 10rpx;
}

.u-body-item image {
	width: 120rpx;
	flex: 0 0 120rpx;
	height: 120rpx;
	border-radius: 8rpx;
	margin-left: 12rpx;
}

.footer {
	margin: 0 30rpx 30rpx;

	/deep/ .uni-pagination__btn {
		background: #fff;
		opacity: 1;
		border-radius: 5px;
	}
}
</style>